import seal from '@/lib/request/seal'
import { RootState } from '@/store'
import { Commit } from 'vuex'
import { IResponse } from '@/lib/service'
import user from '@/lib/request/user'
import payOrder from '@/lib/request/payOrder'

export interface PaymentOrderState {}
const initState: PaymentOrderState = {}

const getters = {}

const actions = {
  getOrderDetail(
    context: {
      commit: Commit
      state: PaymentOrderState
      rootState: RootState
      getters: any
    },
    payload: string
  ) {},
  querySealApplyPayPreOrderInfo(
    context: {
      commit: Commit
      state: PaymentOrderState
      rootState: RootState
      getters: any
    },
    payload: number
  ) {
    // 获取支付订单预查询
    return seal
      .querySealApplyPayPreOrderInfo(payload)
      .then((res: IResponse) => {
        return res.data
      })
  },
  listMyDeliveryAddress(
    context: {
      commit: Commit
      state: PaymentOrderState
      rootState: RootState
      getters: any
    },
    payload: any
  ) {
    // 收货地址列表
    return user.listMyDeliveryAddress().then((res: IResponse) => {
      return res.data
    })
  },
  setAddressAsDefault(
    context: {
      commit: Commit
      state: PaymentOrderState
      rootState: RootState
      getters: any
    },
    payload: any
  ) {
    // 设为默认
    return user.setAddressAsDefault(payload).then((res: IResponse) => {
      return res.data
    })
  },
  deleteDeliveryAddress(
    context: {
      commit: Commit
      state: PaymentOrderState
      rootState: RootState
      getters: any
    },
    payload: any
  ) {
    // 删除
    return user.deleteDeliveryAddress(payload).then((res: IResponse) => {
      return res.data
    })
  },
  queryByOrderId(
    context: {
      commit: Commit
      state: PaymentOrderState
      rootState: RootState
      getters: any
    },
    payload: any
  ) {
    return payOrder.queryByOrderId(payload).then(res => res.data)
  },
  queryPayOrderList(
    context: {
      commit: Commit
      state: PaymentOrderState
      rootState: RootState
      getters: any
    },
    payload: any
  ) {
    return payOrder.queryOrderList(payload).then(res => res.data)
  },
  queryPayOrderInfo(
    context: {
      commit: Commit
      state: PaymentOrderState
      rootState: RootState
      getters: any
    },
    payload: any
  ) {
    return payOrder.queryPayOrderInfo(payload).then(res => res.data)
  },
  queryAllStatusCount(
    context: {
      commit: Commit
      state: PaymentOrderState
      rootState: RootState
      getters: any
    },
    payload: any
  ) {
    return payOrder.queryAllStatusCount().then(res => res.data)
  },
  queryPayOrderCreatedInfo(
    context: {
      commit: Commit
      state: PaymentOrderState
      rootState: RootState
      getters: any
    },
    payload: any
  ) {
    return payOrder.queryPayOrderCreatedInfo(payload).then(res => res.data)
  },
  queryPayOrderStatus(
    context: {
      commit: Commit
      state: PaymentOrderState
      rootState: RootState
      getters: any
    },
    payload: any
  ) {
    return payOrder.queryPayOrderStatus(payload).then(res => res.data)
  },
  confirmPayOrder(
    context: {
      commit: Commit
      state: PaymentOrderState
      rootState: RootState
      getters: any
    },
    payload: any
  ) {
    return payOrder.confirmPayOrder(payload).then(res => res.data)
  },
  invoiceDownLoad(
    context: {
      commit: Commit
      state: PaymentOrderState
      rootState: RootState
      getters: any
    },
    payload: any
  ) {
    return payOrder.invoiceDownLoad(payload)
  },
  invoiceDirect(
    context: {
      commit: Commit
      state: PaymentOrderState
      rootState: RootState
      getters: any
    },
    payload: any
  ) {
    return payOrder.invoiceDirect(payload).then(res => res.data)
  },
  cancelPayOrder(
    context: {
      commit: Commit
      state: PaymentOrderState
      rootState: RootState
      getters: any
    },
    payload: any
  ) {
    return payOrder.cancelPayOrder(payload)
  },
  queryInvoiceProduceStatus(
    context: {
      commit: Commit
      state: PaymentOrderState
      rootState: RootState
      getters: any
    },
    payload: any
  ) {
    return payOrder.queryInvoiceProduceStatus(payload)
  },
}

const mutations = {
  setStateData(state: PaymentOrderState, data: any) {
    // eslint-disable-next-line no-param-reassign
    state = Object.assign(state, data)
  },
}

export default {
  namespaced: true,
  state: initState,
  getters,
  actions,
  mutations,
}
